#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"
#include "../../../../core/shader_color.h"


layout(location = 0) in vec2 inPos;
layout(location = 1) in vec2 inWdigths;

layout(location = 0) out vec4 vColor;
layout(location = 1) out vec2 vUV;
layout(location = 2) out flat float gap;
layout(location = 3) out flat float offset;
layout(location = 4) out flat uint shaderType;
layout(location = 5) out float shaderBlur;
layout(location = 6) out float shaderShadow;
layout(location = 7) out vec2 vScreenPos;

layout(push_constant, scalar) uniform DRAWPROP_push_constants {
	S_ConstPush_2DPolygonElement const_push;
};

layout(std140, set = 0, binding = DEF_BINDING_PROJECT) uniform U_Matrix0 {
	mat4 mat_ProjecView[2];
};

layout(std430, set = 1, binding = 1, scalar, column_major) readonly buffer U_Matrix1 {
	mat3 tranformG[];
};
layout(std430, set = 1, binding = 2, scalar, column_major) readonly buffer U_Matrix2 {
	mat3 tranformL[];
};

layout(std430, set = 2, binding = 1, scalar) readonly buffer U_Matrix3 {
	uvec2 elementColor[];
};


void main(void) {
	mat3 matG = tranformG[const_push.m_Offset_TranformG];
	mat3 matL = tranformL[const_push.m_Offset_TranformL + gl_DrawID];
	uvec2 shaderPack = elementColor[const_push.m_Offset_Color + gl_DrawID];

	
	vec2 vert = inPos * inWdigths;
	vec4 v = vec4(matG * matL * vec3(vert, 1.0), 1.0);
	
	shaderBlur = float(shaderPack.y & 0xff) / 255.0f;
	shaderShadow = float((shaderPack.y >> 8) & 0xff) / 255.0f;
	shaderType = (uint(shaderPack.y >> 16) & 0xff);


	gl_Position = mat_ProjecView[1] * v;
	vColor = f_glsl_buildColor(shaderPack.x);

	vScreenPos = gl_Position.xy / gl_Position.w;
}
